package com.springcloud.hystrixdemo.config

import com.netflix.hystrix.exception.HystrixBadRequestException
import feign.Response
import feign.codec.ErrorDecoder
import org.springframework.context.annotation.Bean

import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock

class FeignConfig {


    /*
        用于解析失败的请求(响应码在300及其以上)
     */
    @Bean
    def errorDecoder()
    {

        new ErrorDecoder() {

            /**
             *
             * @param methodKey 出现错误Feign方法签名
             * @param response  Feign方法请求后的响应
             * @return 抛出一个异常.除了HystrixBadRequestException类外,抛出的异常都会被fallback属性指定的回调类捕获处理
             */
            @Override
            Exception decode(String methodKey, Response response) {
                new HystrixBadRequestException("错误状态码:${response.status()},错误方法:${methodKey}")
            }
        }
    }


}
